/*
 * Copyright 2019 Flipkart Internet Pvt. Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.flipkart.ohos.proteus.support.v7.widget;

import ohos.agp.components.ComponentContainer;
import ohos.agp.components.StackLayout;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;

import com.flipkart.ohos.proteus.ProteusContext;
import com.flipkart.ohos.proteus.ProteusView;
import com.flipkart.ohos.proteus.ViewTypeParser;
import com.flipkart.ohos.proteus.processor.BooleanAttributeProcessor;
import com.flipkart.ohos.proteus.processor.ColorResourceProcessor;
import com.flipkart.ohos.proteus.processor.DimensionAttributeProcessor;
import com.flipkart.ohos.proteus.value.Layout;
import com.flipkart.ohos.proteus.value.ObjectValue;

/**
 * CardViewParser
 *
 * @author adityasharat
 */
public class CardViewParser<T extends StackLayout> extends ViewTypeParser<T> {
    @Override
    public String getType() {
        return "CardView";
    }

    @Override
    public String getParentType() {
        return "StackLayout";
    }

    @Override
    public ProteusView createView(ProteusContext context, Layout layout, ObjectValue data,
                                  ComponentContainer parent, int dataIndex) {
        return new ProteusCardView(context);
    }

    @Override
    protected void addAttributeProcessors() {
        addAttributeProcessor("cardBackgroundColor", new ColorResourceProcessor<T>() {
            @Override
            public void setColor(T view, int color) {
//        view.setBackground(color);
            }

            @Override
            public void setColor(T view, Color color) {
//                view.setBackground(colors);
            }
        });

        addAttributeProcessor("cardCornerRadius", new DimensionAttributeProcessor<T>() {
            @Override
            public void setDimension(T view, float dimension) {
                ShapeElement shapeElement = new ShapeElement();
                shapeElement.setCornerRadius(dimension);
                shapeElement.setShaderType(ShapeElement.LINEAR_GRADIENT_SHADER_TYPE);
                view.setBackground(shapeElement);
            }
        });

        addAttributeProcessor("cardElevation", new DimensionAttributeProcessor<T>() {
            @Override
            public void setDimension(T view, float dimension) {
//                view.setCardElevation(dimension);
            }
        });

        addAttributeProcessor("cardMaxElevation", new DimensionAttributeProcessor<T>() {
            @Override
            public void setDimension(T view, float dimension) {
//                view.setMaxCardElevation(dimension);
            }
        });

        addAttributeProcessor("cardPreventCornerOverlap", new BooleanAttributeProcessor<T>() {
            @Override
            public void setBoolean(T view, boolean value) {
//                view.setPreventCornerOverlap(value);
            }
        });

        addAttributeProcessor("cardUseCompatPadding", new BooleanAttributeProcessor<T>() {
            @Override
            public void setBoolean(T view, boolean value) {
//                view.setUseCompatPadding(value);
            }
        });

        addAttributeProcessor("contentPadding", new DimensionAttributeProcessor<T>() {
            @Override
            public void setDimension(T view, float dimension) {
                view.setPadding((int) dimension, (int) dimension, (int) dimension, (int) dimension);
            }
        });

        addAttributeProcessor("contentPaddingBottom", new DimensionAttributeProcessor<T>() {
            @Override
            public void setDimension(T view, float dimension) {
                int t = view.getPaddingTop();
                int r = view.getPaddingRight();
                int l = view.getPaddingLeft();
                view.setPadding(l, t, r, (int) dimension);
            }
        });

        addAttributeProcessor("contentPaddingLeft", new DimensionAttributeProcessor<T>() {
            @Override
            public void setDimension(T view, float dimension) {
                int t = view.getPaddingTop();
                int r = view.getPaddingRight();
                int b = view.getPaddingBottom();
                view.setPadding((int) dimension, t, r, b);
            }
        });

        addAttributeProcessor("contentPaddingRight", new DimensionAttributeProcessor<T>() {
            @Override
            public void setDimension(T view, float dimension) {
                int t = view.getPaddingTop();
                int b = view.getPaddingBottom();
                int l = view.getPaddingLeft();
                view.setPadding(l, t, (int) dimension, b);
            }
        });

        addAttributeProcessor("contentPaddingTop", new DimensionAttributeProcessor<T>() {
            @Override
            public void setDimension(T view, float dimension) {
                int r = view.getPaddingRight();
                int b = view.getPaddingBottom();
                int l = view.getPaddingLeft();
                view.setPadding(l, (int) dimension, r, b);
            }
        });
    }
}
